import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

def function_avg(x,a=0.65,b=20):
    return 0.5*((np.exp(x-a)-np.exp(-b*(x-a))) / (np.exp(x-a)+np.exp(-b*(x-a)))) + 0.5

print("f 0.55: ", function_avg(0.55))
print("f 0.75: ", function_avg(0.75))

f = open('div_corr.txt', 'r')
lines = f.readlines()
data = np.array([])
for line in lines:
    line = line.strip('\n')
    data = np.append(data, float(line))
print(data.shape)

ax = plt.subplot(2,3,1)
plt.hist(data, bins=100,density=True, histtype='bar', color='#66ccff',cumulative=False)
plt.title('corridor')
# plt.xlabel('diversity index')
# plt.ylabel('percentage/%')
plt.savefig('corridor.png')

bx = plt.subplot(2,3,4)
data = function_avg(data)
plt.hist(data, bins=100,density=True, histtype='bar', color='#66ccff',cumulative=False)
plt.title('corridor')
# plt.xlabel('diversity index')
# plt.ylabel('percentage/%')
# plt.savefig('corridor_avg.png')
# plt.show()




f = open('div_office.txt', 'r')
lines = f.readlines()
data_o = np.array([])
for line in lines:
    line = line.strip('\n')
    data_o = np.append(data_o, float(line))
print(data_o.shape)

plt.subplot(2,3,2,sharex=ax,sharey=ax)
plt.hist(data_o, bins=100,density=True, histtype='bar', color='#66ccff',cumulative=False)
plt.title('office')
# plt.xlabel('diversity index')
# plt.ylabel('percentage/%')
plt.savefig('office.png')



plt.subplot(2,3,5,sharex=bx,sharey=bx)
data_o = function_avg(data_o)
plt.hist(data_o, bins=100,density=True, histtype='bar', color='#66ccff',cumulative=False)
plt.title('office')
# plt.xlabel('diversity index')
# plt.ylabel('percentage/%')
# plt.savefig('office_avg.png')
# plt.show()



f = open('div_ware.txt', 'r')
lines = f.readlines()
data_w = np.array([])
for line in lines:
    line = line.strip('\n')
    data_w = np.append(data_w, float(line))
print(data_w.shape)

plt.subplot(2,3,3,sharex=ax,sharey=ax)
plt.hist(data_w, bins=100,density=True, histtype='bar', color='#66ccff',cumulative=False)
plt.title('warehouse')
# plt.xlabel('diversity index')
# plt.ylabel('percentage/%')
plt.savefig('warehouse.png')



plt.subplot(2,3,6,sharex=bx,sharey=bx)
data_w = function_avg(data_w)
plt.hist(data_w, bins=100,density=True, histtype='bar', color='#66ccff',cumulative=False)
plt.title('warehouse')
# plt.xlabel('diversity index')
# plt.ylabel('percentage/%')
# plt.savefig('warehouse_avg.png')
plt.show()

# data_w = np.where((data_w>=0.55) & (data_w<=0.75),1,0)
# total = np.sum(data_w)
# print("percentage of diversity index between 0.55 and 0.75: ", total/len(data_w))